// pages/index/brandsku/brandsku.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    productlist:'',
    thispNum: '',
    pageEnd: false,
    bottom_tap: false,
    name:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.func.onPageLoad(this, options);
    app.func.getPromise(`/topicSku/${options.id}/0?length=0`)
        .then(([code,res])=>{
          if(code == 200){
            console.log(res);
            this.setData({
              productlist:res.data.sku,
              cover:res.data.cover,
              thispNum: res.data.sku.length,
              topic_id:options.id
            });
            wx.setNavigationBarTitle({title: res.data.name});
          }
        })
  },

  collectChange(e) {
    let data = e.detail;
    this.setData({
      [`productlist[${data.index}].add_cart`]: data.value
    });
  },


  /**
   * 页面上拉触底事件的处理函数
  
  onReachBottom: function () {
    if (this.data.pageEnd) {
      this.setData({  bottom_tap: true });
    } else {
      wx.showLoading({  title: '加载更多', mask: true });
      var thispNum = this.data.thispNum;
      var topic_id = this.data.topic_id;
      var that = this;
      app.func.getPromise(`/topicSku/${topic_id}/${thispNum}?length=20`)
          .then(([code,res])=>{
            if (res.data.length == 0) {
              that.setData({
                pageEnd: true,
                bottom_tap: true
              }, ()=> wx.hideLoading())
            } else {
              var tempArray = that.data.productlist;
              tempArray = tempArray.concat(res.data);
              that.setData({
                productlist: tempArray,
                thispNum: that.data.thispNum + res.data.length
              }, ()=> wx.hideLoading());
            }
          })
    }
  },
 */


  login:function () {
    wx.navigateTo({
      url:'/pages/auth/auth'
    })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }


})
